package br.usjt.component.login.model;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.envers.Audited;
import org.hibernate.validator.constraints.NotBlank;

@Audited
@Entity
@Table(name = "RESOURCE")
@SequenceGenerator(name = "resource_gen", sequenceName = "RESOURCE_SEQ", initialValue = 1, allocationSize = 50)
public class Recurso extends AbstractEntity<Integer> implements Serializable {

    private static final long serialVersionUID = -3726855994945590172L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "resource_gen")
    @Column(name = "RESOURCE_ID")
    private Integer id;

    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "ROLE_ID_FK", nullable = true, insertable = true, updatable = true)
    private Perfil perfil;

    @Column(name = "PAGE")
    private String nomePagina;

    @NotBlank
    @NotNull
    @Column(name = "URL")
    private String url;

    @Column(name = "DESCRIPTION")
    private String descricao;

    @Column(name = "STATUS", length = 1, nullable = false)
    private Boolean status = false;

    public Perfil getPerfil() {
        return perfil;
    }

    public boolean isStatus() {
        return status;
    }

    public String getNomePagina() {
        return nomePagina;
    }

    public String getUrl() {
        return url;
    }

    public String getDescricao() {
        return descricao;
    }

    public Integer getId() {
        return id;
    }

    public void setNomePagina(String nomePagina) {
        this.nomePagina = nomePagina;
    }

    public void setPerfil(Perfil perfil) {

        this.perfil = perfil;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((descricao == null) ? 0 : descricao.hashCode());
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((nomePagina == null) ? 0 : nomePagina.hashCode());
        result = prime * result + ((perfil == null) ? 0 : perfil.hashCode());
        result = prime * result + ((status == null) ? 0 : status.hashCode());
        result = prime * result + ((url == null) ? 0 : url.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!super.equals(obj)) {
            return false;
        }
        if (!(obj instanceof Recurso)) {
            return false;
        }
        Recurso other = (Recurso) obj;
        if (descricao == null) {
            if (other.descricao != null) {
                return false;
            }
        } else if (!descricao.equals(other.descricao)) {
            return false;
        }
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        if (nomePagina == null) {
            if (other.nomePagina != null) {
                return false;
            }
        } else if (!nomePagina.equals(other.nomePagina)) {
            return false;
        }
        if (perfil == null) {
            if (other.perfil != null) {
                return false;
            }
        } else if (!perfil.equals(other.perfil)) {
            return false;
        }
        if (status == null) {
            if (other.status != null) {
                return false;
            }
        } else if (!status.equals(other.status)) {
            return false;
        }
        if (url == null) {
            if (other.url != null) {
                return false;
            }
        } else if (!url.equals(other.url)) {
            return false;
        }
        return true;
    }

}
